#pragma once
#include<iostream>
#include<vector>
#include<functional>
using namespace std;
namespace hcc
{
	template<class T,class container = std::vector<T> ,class compare = hcc::less<T>>
	class priority_queue
	{
	public:
		void adjustup(int child)
		{
			int parent = (child - 1) / 2;
			while (parent >= 0 && child > 0)
			{
				if (_c(_con[child],_con[parent]))
					std::swap(_con[child], _con[parent]);
				child = parent;
				parent = (child - 1) / 2;
			}
		}
		size_t size() const 
		{
			return _con.size();
		}
		T& top()
		{
			return _con[0];
		}
		void push(const T& x)
		{
			_con.push_back(x);
			adjustup(_con.size() - 1);
		}
		void adjustdown(int parent)
		{
			int child = parent * 2 + 1;
			while ((child + 1) < (int)size())
			{
				if (!_c(_con[child], _con[child + 1]))
					child = child + 1;
				if (_c(_con[child], _con[parent]))
					std::swap(_con[child], _con[parent]);
				parent = child;
				child = parent * 2 + 1;
			}
		}
		void pop()
		{
			std::swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();
			adjustdown(0);
		}
		bool empty() const
		{
			return _con.size() == 0;
		}
	private:
		container _con;
		compare _c;
	};
	template<class T>
	struct less
	{
		bool operator()(const T& x, const T& y)
		{
			return x > y;
		}
	};
	template<class T>
	struct greater
	{
		bool operator()(const T& x, const T& y)
		{
			return x < y;
		}
	};
}
